package com.goldgov.jsondoc.revsoler.impl;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import com.goldgov.jsondoc.revsoler.JsonRevsoler;

public class UrlJsonRevsoler implements JsonRevsoler {

	public String getJsonFromUrl(String url) throws Exception {
		URL u = new URL(url);
		URLConnection connection = u.openConnection();
		InputStream inputStream = connection.getInputStream();
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		
		StringBuffer sb = new StringBuffer();
		String text = null;
		while((text = bufferedReader.readLine()) != null) {
			sb.append(text);
		}
		bufferedReader.close();
		return sb.toString();
	}

}
